package com.teafriend.controller;

import com.teafriend.entity.Admin;
import com.teafriend.service.AdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户控制器
 * @author 欧楚杨
 */
@RestController
@RequestMapping("/chuyangc/admin/")
@Api(tags = "用户相关的请求")
public class AdminController {
    @Autowired
    AdminService adminService;

    @GetMapping("/listadmin")
    @ApiOperation("查询所有用户")
    @ApiImplicitParam()
    public List<Admin> listAdmin(){
        return adminService.list();
    }

    @DeleteMapping("/deladmin/{id}")
    @ApiOperation("根据用户id删除数据")
    @ApiImplicitParam(name = "用户id",value = "id",required = true)
    public boolean delAdmin(@PathVariable("id") Integer id){
        return adminService.removeById(id);
    }

    @PostMapping("/addadmin")
    @ApiOperation("添加用户")
    @ApiImplicitParam(name = "用户实体对象",value = "admin",required = true)
    public boolean addAdmin(@RequestBody Admin admin){
        return adminService.save(admin);
    }

    @GetMapping("/searchadmin/{id}")
    @ApiOperation("根据id查找用户")
    @ApiImplicitParam(name = "用户id",value = "id",required = true)
    public Admin searchAdmin(@PathVariable Integer id){
        return adminService.getById(id);
    }

    @PostMapping("/updateadmin")
    @ApiOperation("根据用户id修改密码")
    @ApiImplicitParam(name = "用户实体对象",value = "admin",required = true)
    public boolean updateAdmin(@RequestBody Admin admin){
        return adminService.updateById(admin);
    }
}
